﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace HCLSMod
{
    public class RichTextGoBottom
    {
        const int WM_VSCROLL = 0x0115;
        const int SB_BOTTOM = 7;

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        /// <summary>
        /// 将目标多行文字对象的当前工作位置移动到底部
        /// </summary>
        /// <param name="RichTextBoxHandle">多行文字对象的句柄</param>
        public static void GoBottom(IntPtr RichTextBoxHandle)
        {
            if (RichTextBoxHandle != IntPtr.Zero)
                // 将显示位置移动到最后
                SendMessage(RichTextBoxHandle, WM_VSCROLL, SB_BOTTOM, 0);
        }
        /// <summary>
        /// 将目标多行文字对象的当前工作位置移动到底部
        /// </summary>
        /// <param name="fRichTextBox">多行文字对象</param>
        public static void GoBottom(RichTextBox fRichTextBox)
        {
            if (fRichTextBox != null)
                // 将显示位置移动到最后
                SendMessage(fRichTextBox.Handle, WM_VSCROLL, SB_BOTTOM, 0);
        }
    }
}
